package cv.gzd.robot.socket;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

import javax.annotation.Resource;

/**
 * @Author: Jun
 * @Date: 2018/8/21 14:54
 */
@Component
@EnableWebSocket
public class WebSocketConfig extends WebMvcConfigurerAdapter implements WebSocketConfigurer {

    @Resource
    SystemWebSocketHandler systemWebSocketHandler;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry webSocketHandlerRegistry) {
        webSocketHandlerRegistry.addHandler(systemWebSocketHandler, "/ws")
                .addInterceptors(new Handshake());
        webSocketHandlerRegistry.addHandler(systemWebSocketHandler, "/ws/sockjs")
                .addInterceptors(new Handshake())
                .withSockJS();
    }
    
}